
# 查询需要下载附件的公司
from base.BaseMethod import BM
from util.DataQuery.DbTools import DbTools
from util.pdfSplit.compress_pdf import CompressPdf
from util.pdfSplit.pdf_split import get_file_oss

sql = 'select s.co_id, s.entname from hitech.ent_res_status s,hzflow.ent_flow_datalog l where s.file_stat like "%ctp:1%" and s.co_id = l.co_id and l.update_time between "2021-06-19 00:00:00" and "2021-06-29 23:59:59" and s.ul_status in (2) group by s.co_id order by l.update_time '

sql = """
select * from ent_res_status where year=2021 and res_code="GR" and co_id in (409053475604,475591,96334,561077,987251,987181,379093,388540,81424,985181,409629,860306,71900,478255,953368,117075)
"""


sql = """
select * from ent_res_status where year=2021 and res_code='GR' and entname in ('江苏易图地理信息科技有限公司','昆山兴鸿蒙电子有限公司','昆山新合宇制辊有限公司','常州瀚中数据有限公司','长驰传动科技（苏州）有限公司','苏州旭辉检测有限公司','昆山圆宜方电子有限公司','江苏原木环境科技有限公司','常州腾炬机械制造有限公司','常州新视界数字科技有限公司','威世特汽车部件（常州）有限公司','常州国洁环保科技有限公司','江苏新中天塑业有限公司','常州东木橡塑制品有限公司','常州市源长新材料科技有限公司','江苏颐海药业有限责任公司','兴勤（常州）电子有限公司')
"""

data = DbTools.get_hitech_record_by_sql(sql=sql, model="all")
for co in data:
    co_id = co.get("co_id")
    entname = co.get("entname")
    # 查询附件
    sql = f"SELECT oss_path FROM `hitech`.`ent_res_pdf` WHERE `co_id` = '{co_id}' AND `rule_id` = '6' AND `res_code` = '2020' AND `year` = '2021'"
    file_obj = DbTools.get_hitech_record_by_sql(sql=sql)
    oss_path = file_obj.get("oss_path")
    file_path = f"\\\\MOURNER\\share\\17\\{'{}_{}'.format(entname, co_id)}.pdf"
    print(file_path)
    oss_file = get_file_oss(oss_path=oss_path, local_path=file_path + ".pdf")
    BM.wait_file(file_path=oss_file)
    CompressPdf(file_path=oss_file, max_size=8).compress()
    BM.wait_file(file_path=file_path)


